package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.extension.BaseFormInfo;
import com.alpha.eceasy.mall.api.entity.MallOrderDetail;
import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.service.MallOrderDetailService;
import com.alpha.eceasy.mall.service.impl.MallOrderDetailServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 订单详情
 *
 * @author huangpengfei
 * @since 2022-02-11 16:55:59
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/order-detail")
@Hidden
@Tag(description = "order-detail", name = "订单详情")
public class MallOrderDetailController {
    private final MallOrderDetailServiceImpl mallOrderDetailService;

    /**
     * 分页查询
     *
     * @param page           分页对象
     * @param payOrderDetail 订单详情
     * @return 分页结果
     */
    @GetMapping("")
    public R<IPage<MallOrderDetail>> getPayOrderDetailPage(Page<MallOrderDetail> page, MallOrderDetail payOrderDetail) {
        return R.ok(mallOrderDetailService.page(page, Wrappers.lambdaQuery(payOrderDetail)
                .eq(BaseFormInfo::getDeleted, false)));
    }

    /**
     * 通过id查询订单详情
     *
     * @param guid guid
     * @return R 返回结果 订单详情
     */
    @GetMapping("/{guid}")
    public R<MallOrderDetail> getById(@PathVariable("guid") String guid) {
        return R.ok(mallOrderDetailService.getByGuid(guid));
    }

    /**
     * 新增订单详情
     *
     * @param payOrderDetail 订单详情
     * @return R 返回结果 是否成功
     */
    //@SysLog("新增订单详情")
    @PostMapping
    public R<Boolean> save(@RequestBody MallOrderDetail payOrderDetail) {
        return R.ok(mallOrderDetailService.save(payOrderDetail));
    }

    /**
     * 修改订单详情
     *
     * @param payOrderDetail 订单详情
     * @return R 返回结果 是否成功
     */
    //@SysLog("修改订单详情")
    @PutMapping
    public R<Boolean> updateById(@RequestBody MallOrderDetail payOrderDetail) {
        return R.ok(mallOrderDetailService.updateByGuid(payOrderDetail));
    }

}
